package com.gxa.admin.controller;

import com.gxa.admin.pojo.dto.EmployeeDto;
import com.gxa.admin.service.EmployeeService;
import com.gxa.admin.utils.QueryResult;
import com.gxa.core.result.MessageCode;
import com.gxa.core.result.Result;
import com.gxa.core.result.ResultUtils;
import com.gxa.pojo.Vip;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description
 * @author: RicksonYu
 * @create: 2024年-03月-20日--18:23
 */
@RestController
@RequestMapping("/admin/employee")
public class EmployeeController {

    @Autowired
    EmployeeService employeeService;

    @PostMapping("/getAllEmployees")
    public Result queryAllEmployee(@RequestBody EmployeeDto employeeDto){

        QueryResult queryResult = employeeService.queryAll(employeeDto);

        System.out.println(queryResult);
        if (queryResult != null) {
            return ResultUtils.buildSuccess(queryResult.getCount(), queryResult.getData());        }

            return ResultUtils.buildFail(MessageCode.UN_KNOW_EXCEPTION);
    }

    /**
     * @deprecated addEmployee使用EmpController接口替代(需对密码进行加密)
     * @see EmpController
     * 添加时需对密码加密
     */
//    @PostMapping("/addEmployee")
    public Result saveEmployee(@RequestBody EmployeeDto employeeDto) {
        int result =  employeeService.addEmployee(employeeDto);

        System.out.println(employeeDto);

        if (result > 0) {

            //添加成功
            return ResultUtils.buildFail(MessageCode.REQUEST_SUCCESS);
        } else {
            //添加失败
            return ResultUtils.buildSuccess(MessageCode.REQUEST_SUCCESS);
        }
    }


    /**
     * @deprecated 用EmpController类的接口替代
     * @see EmpController
     * 修改密码时需对密码进行加密
     */
//    @PostMapping("/updateEmployeeMsg")
    public Result editEmploy(@RequestBody EmployeeDto employeeDto) {

        int result = employeeService.updateEmploy(employeeDto);
        if (result > 0) {

            //添加成功
            return ResultUtils.buildFail(MessageCode.REQUEST_SUCCESS);
        } else {
            //添加失败
            return ResultUtils.buildSuccess(MessageCode.REQUEST_SUCCESS);
        }
    }

    //删除操作
//    @PostMapping("/deleteEmployeeById")
    public Result deleteBy(String employeeId){
        employeeService.deleteBannerById(employeeId);
        return ResultUtils.buildSuccess();
    }
}
